import feedparser
from typing import List, Dict

# 预定义的AI行业博客RSS源
INDUSTRY_FEEDS = {
    "OpenAI Blog": "https://openai.com/blog/rss.xml",
    "DeepMind Blog": "https://deepmind.google/blog/rss.xml",
    "Anthropic Blog": "https://www.anthropic.com/news/rss.xml",
    "Hugging Face Blog": "https://huggingface.co/blog/feed.xml",
}

def fetch_industry_news(feeds: Dict[str, str] = None) -> List[Dict]:
    """
    从指定的RSS源获取行业新闻。

    :param feeds: 包含博客名称和RSS链接的字典，如果为None，则使用预定义的列表。
    :return: 包含新闻信息的字典列表。
    """
    if feeds is None:
        feeds = INDUSTRY_FEEDS

    all_news = []
    for blog_name, feed_url in feeds.items():
        print(f"Fetching news from {blog_name}...")
        try:
            feed = feedparser.parse(feed_url)
            for entry in feed.entries:
                all_news.append({
                    "source": blog_name,
                    "title": entry.title,
                    "summary": entry.summary,
                    "link": entry.link,
                    "published": entry.get("published", "N/A"),
                })
        except Exception as e:
            print(f"Error fetching feed from {blog_name}: {e}")
            
    return all_news

if __name__ == '__main__':
    industry_news = fetch_industry_news()
    for news_item in industry_news:
        print(f"Source: {news_item['source']}\nTitle: {news_item['title']}\n---")